import { useMutation, useQuery } from "react-query";
import { useRequest } from "../../utils/request";
import { IPage, IPageParams } from "../../types";



/**
 * !获取到带指派的人员
 */
export const getAssignUserList = () => {
    const request = useRequest<ISys[]>();
    return useQuery(['sys'], () =>
        request('/sys/getAllSysOfSq', {  }),
    );
}
/**
 * !搜索管理员接口
 * @returns 
 */

export const useGetSysBySearch = (queryParams: ISysSearchParams) => {
    const request = useRequest<IPage<ISys>>();
    return useQuery(['sys', queryParams], () =>
        request('/sys/getSysBySearch', { data: queryParams }),
    );
};

/**
 * ! 添加管理员接口
 * @returns 
 */

export const useAddSys = () => {
    const request = useRequest<string>();
    return useMutation(async (params: IAddSys) => {
        const result = request('/sys/addSys', {
            data: params,
            method: 'PUT',
        });
        return result;
    });
}


/**
 * !更新管理员信息
 * @returns 
 */
export const useUpdateSys = () => {
    const request = useRequest<string>();
    return useMutation(async (params: IUpdateSys) => {
        const result = request('/sys/updateSys', {
            data: params,
            method: 'POST',
        });
        return result;
    });
}


/**
* !删除管理员接口
*/
export const useDeletedSysById = () => {
    const request = useRequest<string>();
    return useMutation(async (params: { sysId: string }) => {
        const result = request('/sys/deleteSysById', {
            data: params,
            method: 'DELETE',
        });
        return result;
    });
}


export type ISysSearchParams = {
    sysName: string;
    unitId: string;
} & IPageParams;







/**
 * 添加管理员的类型
 */
export type IAddSys = {
    sysName: string;
    sysPassword: string;
    unitId: string;
    phone: string;
    sysNickName: string | undefined;
    sysRoleId: number;
    sysAvater: string | undefined;
}



/**
 * 更新管理员的类型
 */
export type IUpdateSys = {
    sysId: number;
} & Partial<IAddSys>;



/**
 * 管理员
 */
export type ISys = {
    /**
    * 管理员ID
    */
    sysId: string;
    /**
     * 管理员登录名称
     */
    sysName: string;
    /**
     * 管理员密码
     */
    sysPassword: string;
    /**
    * 管理员登录昵称
    */
    sysNickName: string;
    /**
     * 创建时间
     */
    createTime: string;
    /**
     * 更新时间
     */
    updateTime: string;
    /**
     * 管理员头像
     */
    sysAvater: string;
    /**
     * 所属单位ID
     */
    unitId: string;
    /**
     * 单位名称
     */
    unitName: string;
    /**
     * 角色ID
     */
    sysRoleId: number;
    /**
     * 手机号码
     */
    phone: string;
    /**
     * 社区单位ID
     */
    sqUnitId: string;
}